package com.huluobo.lc.kotlinim1803a.data.db

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import com.huluobo.lc.kotlinim1803a.IMApplication
import org.jetbrains.anko.db.*

/**
 * @author Lc
 * @description:
 * @date :2020/9/28 16:04
 */
class DatabaseHelper(ctx: Context = IMApplication.instance) :
    ManagedSQLiteOpenHelper(ctx, NAME, null, VERSION) {

    companion object {
        const val NAME = "im.db"
        const val VERSION = 1
    }

    override fun onCreate(db: SQLiteDatabase?) {
        db?.createTable(
            ContactTable.NAME,//表明
            true,//是否存在于当前数据库中
            ContactTable.ID to INTEGER + PRIMARY_KEY + AUTOINCREMENT, //id代表int值,主键,自增
            ContactTable.CONTACT to TEXT
        )
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        db?.dropTable(ContactTable.NAME, true)
        onCreate(db)
    }
}